(function(){
	var vizPlugin = Ext.ux.plugin && Ext.ux.plugin.VisibilityMode ? new Ext.ux.plugin.VisibilityMode({hideMode:'nosize',elements:['bwrap']}):{init:Ext.emptyFn};
		vizPlugin = {init:Ext.emptyFn};
		App.MIFTreeNav || (App.MIFTreeNav = Ext.extend(App.Window,{
			hideMode:'display',
			border:false,
			animCollapse:false,
			closeAction:'close',
			defaults:{split:false,border:false,frame:true},
			plugins:[vizPlugin],
			layout:'border',
			initComponent:function(){
				var me=this;
				this.items=[
					{
					region:'west',
					ref:'navTree',
					xtype:'treepanel',
					title:'Quản trị web',
					id:'westmenu',
					minWidth:160,
					width:160,
					maxSize:160,
					split:false,
					collapsible:false,
					autoScroll:true,
					containerScroll:true,
					margins:'5 5 5 5',
					bodyStyle:'background-color: #fff;',
					rootVisible:false,
					lines:false,
					border:true,
					root:{
						draggable:false,
						expanded:true,
						leaf:false,
						children:this.staticNodes
					},
					loader:new Ext.tree.TreeLoader({
						preloadChildren:true,
						baseAttrs:{
							iconCls:'http',
							leaf:true,
							frameTitle:'Loading...'
						}
					}),
					listeners:{
						beforerender:function(tree){
							tree.getSelectionModel().on('selectionchange',this.onSelectNode,this)
						},scope:this
					}
				},{
					xtype:'tabpanel',
					id:this.getId()+'-center',
					ref:'appTabs',
					activeTab:0,
					margins:'5 5 5 0',
					frame:true,
					defaults:{split:true,border:false,frame:true},
					region:'center',
					frame:true,
					require:['@mif','/templates/ext/ux/crc32'],
					layoutOnTabChange:true,
					defaults:{
						xtype:'iframepanel',
						id:'frame-content',
						hideMode:'display',
						autoScroll:true,
						frame:true,
						focusOnLoad:true,
						closable:true,
						listeners:{
							documentloaded:function(frame){
								var MIF=frame.ownerCt, doc=MIF.getFrameDocument(), sameOrigin=frame.domWritable();
								/*var title=sameOrigin?doc.title:null;*/
								var node=MIF.selectedNode;
								if(node){
									title=node.attributes.text;node.getUI().afterLoad()
								}
								title&&MIF.setTitle(title,sameOrigin?'frame-open':'frame-locked')
							},scope:this
						}
					}
				}];
				App.MIFTreeNav.superclass.initComponent.apply(this,arguments)
			},
			staticNodes:[
				{text: '<a href="javascript:;"> Bài viết </a>', leaf : false, expanded : false,
				children: [
					{ text:' Danh mục b-viết ', tabRef: 'acat',  url : '/article/cat/index'},
					{ text:' Bài viết', tabRef: 'article' ,  url : '/article/admin/index'}
				]},
				{text: '<a href="javascript:;"> Sản phẩm </a>', leaf : false, expanded : false,
				children: [
					{ text:' Danh mục s-phẩm', tabRef: 'pcat',  url : '/product/cat/index'},
					{ text:' Sản phẩm', tabRef: 'product' ,  url : '/product/admin/index'}
				]},
				{ text:' Liên kết', tabRef: 'link' ,  url : '/link/admin/index'},
				{ text:' Yahoo Support', tabRef: 'yahoo' ,  url : '/yahoo/admin/index'},
				{ text:' Liên hệ', tabRef: 'contact' ,  url : '/contact/admin/index'},
				{ text:' Cấu hình', tabRef: 'cfg' ,  url : '/cfg/admin/index'},
				{ text:' Đổi mật khẩu', tabRef: 'pass' ,  url : '/user/admin/index'},
				{ text:' Thoát', tabRef: 'logout' ,  url : '/admincp/logout'}
			],
			
			onSelectNode:function(sm,node){
				if(!node||!node.leaf)return false;
				var NA=node.attributes,
				URL=NA.url,
				tabId='frame-'+NA.tabRef,title=(URL?NA.frameTitle:null)||NA.text,
				tabs=this.appTabs,
				tab=tabs.getItem(tabId);
				
				tab||(tab=tabs.add({
						id:tabId,frameConfig:{id:'fr-'+NA.tabRef},
						title:title,
						defaultSrc:URL,
						html:NA.html,
						data:NA.data,
						tpl:NA.tpl,
						iconCls:URL?'loading-indicator':null,
						loadMask:URL?{msg:'Đang tải dữ liệu, xin vui lòng đợi...'}:false,
						listeners:NA.listeners,selectedNode:node
					}
				));
				
				if(!tab.rendered){
					URL&&node.getUI().beforeLoad();
					tabs.doLayout()
				}
				node.ownerTree.getSelectionModel().clearSelections();
				tabs.setActiveTab(tab)
			},
			sourceModule:App.resolveURL('mif','treenav.js')
		}
	));
	
	$JIT.provide('treenav')
})();